 <!DOCTYPE html>
<html> 
<head> 
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">  
    <title>检测机构管理</title> 
    <link rel="shortcut icon" href="favicon.ico">
	<#import "/common/import.ftl" as import>
    <@import.tableManagerImportCss/>
    <link href="${WEB_PATH}/resources/css/plugins/treeview/bootstrap-treeview.css" rel="stylesheet">
    <link href="${WEB_PATH}/resources/css/plugins/jsTree/style.min.css" rel="stylesheet">
    <style>
    	.demo:after {
		    background-color: #F5F5F5;
		    border: 1px solid #DDDDDD;
		    border-radius: 4px 0 4px 0;
		    color: #9DA0A4;
		    content: "条件查询：";
		    font-size: 12px;
		    font-weight: bold;
		    left: -1px;
		    padding: 3px 7px;
		    position: absolute;
		    top: -1px;
		}
		.demo {
		    margin-left: 0px;
		    padding:40px 15px 0px;
		    border: 1px solid #DDDDDD;
		    border-radius: 4px;
		    position: relative;
		    word-wrap: break-word;
		}
		.tsorgInfo:after {
		    background-color: #F5F5F5;
		    border: 1px solid #DDDDDD;
		    border-radius: 4px 0 4px 0;
		    color: #9DA0A4;
		    content: "详细信息：";
		    font-size: 12px;
		    font-weight: bold;
		    left: -1px;
		    padding: 3px 7px;
		    position: absolute;
		    top: -1px;
		}
		.tsorgInfo {
		    margin-left: 0px;
		    padding:40px 15px 0px;
		    border: 1px solid #DDDDDD;
		    border-radius: 4px;
		    position: relative;
		    word-wrap: break-word;
		}
		.tsorgMap:after {
		    background-color: #F5F5F5;
		    border: 1px solid #DDDDDD;
		    border-radius: 4px 0 4px 0;
		    color: #9DA0A4;
		    content: "所在位置：";
		    font-size: 12px;
		    font-weight: bold;
		    left: -1px;
		    padding: 3px 7px;
		    position: absolute;
		    top: -1px;
		}
		.tsorgMap {
		    margin-left: 0px;
		    padding:40px 15px 0px;
		    border: 1px solid #DDDDDD;
		    border-radius: 4px;
		    position: relative;
		    word-wrap: break-word;
		    margin-top: 10px;
		}
		.map_coordinate {width:100%; height:330px;overflow: hidden;margin:0;}
		.search{
		    width:300px;
		}
    </style>
    <link href="${WEB_PATH}/resources/js/plugins/fancybox/jquery.fancybox.css" rel="stylesheet">
</head>

<body class="gray-bg"> 
    <div class="wrapper wrapper-content  animated fadeInRight"> 
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5><font id="ssbm_name"></font>检测机构管理</h5>
                <div class="ibox-tools">
                </div>
            </div>
            <div class="ibox-content">
                <div class="row row-lg">  
                    <div class="col-sm-12">
                        <!-- Example Events -->
                        <div class="example-wrap"> 
                            <div class="example"> 
                            		<div style="" class="demo ui-sortable">
                            		 <div class="row" style="padding-bottom: 10px;"> 
                            		 	<#if userType != "jcjg">
			                            <div class="col-sm-5">
			                                <div class="form-group">
			                                    <label>所在地区：</label>
            									<input id="QXZQHMC" name="QXZQHMC" class="form-control" readonly type="text" value="" >
												<input id="QXZQHDM" name="QXZQHDM" type="hidden" >
			                                </div>
			                            </div>
			                            <div class="col-sm-3" id="organization_id" >
						                    <div class="form-group">
						                        <label>所属组织部门：</label>
						                         <div class="input-group colorpicker-demo2 colorpicker-element">
								                    <input id="organizationName" name="organizationName" class="form-control dropdown-toggle" readonly type="text" placeholder="请选择组织部门"    style="background-color: #fff;" >
								            		<input id="organizationId" name="organization.ID"  type="hidden"    >
								            		<input id="organization_code" name="organization_code"  type="hidden"   >
								                	<span class="dropdown-toggle input-group-addon  btn btn-white btn-bitbucket" data-toggle="dropdown" id="organization"><i class="fa fa-user-md"></i></span>
								                	<div class="dropdown-menu m-t-xs pull-right" id="organization_tree" style="width: 100%;">
								                        <div id="organizationTree" style="padding: 10px;height:300px;overflow-y:scroll;"></div>
								                    </div>
								                </div>
											</div>
						                </div>   
			                            <div class="col-sm-3" style="padding-top: 22px;">
			                                 <button type="button" class="btn btn-primary" id="search"><i class="fa fa-search"></i>&nbsp;&nbsp;查询</button>
			                            </div> 
			                            </#if>
			                        </div>
			                    </div>
                                <div class="btn-group hidden-xs" id="exampleTableEventsToolbar" role="group">
                                 <@menuCheckInfo url = "/reg/tsorganization/save.do">
                                	<#if urlCheck == true>
                                	<button type="button" class="btn btn-outline btn-default" data-toggle="modal" id="addTestReg" >
                                        <i class="glyphicon glyphicon-plus" aria-hidden="true"></i>&nbsp;&nbsp;新增检测机构
                                    </button>
                                    </#if>
                                </@menuCheckInfo>
                                <@menuCheckInfo url = "/reg/tsorganization/edit.do">
                                	<#if urlCheck == true>
                                    <button type="button" class="btn btn-outline btn-default" data-toggle="modal" id="editTestReg" >
                                        <i class="glyphicon glyphicon-edit" aria-hidden="true"></i>&nbsp;&nbsp;修改检测机构
                                    </button>
                                    </#if>
                                </@menuCheckInfo>
                                <@menuCheckInfo url = "/reg/tsorganization/remove.do">
                                	<#if urlCheck == true>
                                    <button type="button" class="btn btn-outline btn-default" data-toggle="modal" id="delTestReg" >
                                        <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>&nbsp;&nbsp;删除检测机构
                                    </button> 
                               		</#if>
                               </@menuCheckInfo>
                               <@menuCheckInfo url = "/reg/tsorganization/editkey.do">
                                	<#if urlCheck == true>    
                                     <button type="button" class="btn btn-outline btn-default" data-toggle="modal" id="resetTestRegKey" >
                                        <i class="iconfont" style="font-size:14px;font-style:normal;" >&#xe624;</i>&nbsp;&nbsp;重置KEY
                                    </button>
                                    </#if>
                                </@menuCheckInfo> 
                                </div>
                                <table id="exampleTableEvents"  data-mobile-responsive="true" >
                                    <thead>
                                        <tr>
                                            <th data-field="state" data-radio="true"></th>  
                                            <th data-field="ID" data-visible = "false" >id</th>  
								            <th data-field="JYJGBH" >检验机构编号</th> 
								            <th data-field="JYJGMC" >检验机构名称</th>  
								            <th data-field="SSBMCODE" >组织机构代码</th>  
								            <th data-field="SSBMNAME" >所属部门</th>
								            <th data-field="XZQHMC">所在地区</th>
										    <th data-field="KZHJRQ" data-formatter="formatTime">注册日期</th>
										    <th data-field="LINECOUNT"  >检测线数量</th>
								            <th data-field="JYJGZD"  data-formatter="formatterStatus">检验机构状态</th> 
								            
                                        </tr>
                                    </thead>
                                </table>
                            </div>
                        </div>
                        <!-- End Example Events -->
                    </div>
                </div>
            </div>
        </div> 
    </div> 
    <@import.tableManagerImportScript/>
    <script src="${WEB_PATH}/resources/js/plugins/jsTree/jstree.min.js"></script>
    <script src="${WEB_PATH }/resources/js/plugins/fancybox/jquery.fancybox.js"></script>
    <script src="${WEB_PATH}/resources/js/qcity-picker.data.js"></script>
	<script src="${WEB_PATH}/resources/js/city-picker.js"></script>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.5&ak=B3f7707c25da5b29a6ff69618788a296"></script>
    <script >
        var tsorgid="",tsorgzbdz="";
    	$(function(){
    		$(window).resize(function () {
		        $('#exampleTableEvents').bootstrapTable('resetView');
		    });
		    <#if userType != "jcjg">
		    $('#QXZQHMC').citypicker({areaId:'QXZQHDM'});
		    $("#organization").on("click",function(){
				var display =$('#organization_tree').css('display');
				if(display == 'none'){
				  $("#organization_tree").show();
				}else{
				  $("#organization_tree").hide();
				}
			});
			$('#organizationTree').jstree({'core' : {
				 'data': ${json}
			}}).bind("loaded.jstree", function () { 
	        }).bind('changed.jstree', function(event,data) {
	           $("#organizationName").val(data.node.text);
		       $("#organizationId").val(data.node.original.id);
		       $("#organization_code").val(data.node.original.qcode);
		       $("#organization_tree").hide();
		    });
		    </#if>
		    function queryParams(params) {
		        var temp = {  
			        limit: params.limit,  
			        offset: params.offset,  
			        SSBMCODE:$("#organization_code").val(),
			        XZQHDM:$("#QXZQHDM").val(),
			        search:params.search,
			        maxrows: params.limit,
			        pageindex:params.pageNumber,
		        };
		        return temp;
			}
    		//加载table数据
	    	$("#exampleTableEvents").bootstrapTable({
	            url: "${WEB_PATH }/reg/tsorganization/getPage.do",
	            method: 'get',
	            search:true,
	            pagination:true,
	            pageNumber:1,  
	            pageSize:10,   
	            showRefresh:true, 
	            showColumns:true,
	            detailView:true,
	            iconSize: "outline",
	            toolbar: "#exampleTableEventsToolbar",
	            sidePagination: "server", //设置为服务器端分页
	            queryParams: queryParams,//参数
	            minimumCountColumns: 1, 
	            search: true,    //隐藏搜索框
	            clickToSelect: true,  
	            onExpandRow:subTableFormatter
	        });
	        $('input.form-control.input-outline').attr("placeholder","请输入检测机构名称/编号/组织机构号"); //设置搜索提示信息
	        
        });
         //点击查询搜索
		$("#search").click(function(){
			$("#exampleTableEvents").bootstrapTable('refresh');
		});
		//点击新增按钮
		$("#addTestReg").click(function(){ 
			layer.open({
			      type: 2,
			      title: '<span style="color: #ed5565">新增检测机构</span>',
			      shadeClose: false, 
			      shade: 0.3,
			      maxmin: false, //开启最大化最小化按钮
			      area: ['75%', '65%'],
			      content: "${WEB_PATH }/reg/tsorganization/view/add.do",
			      btn: ['确定','取消'],
			      yes: function(index, layero){
				      var body = layer.getChildFrame('body', index);
				      var iframeWin = window[layero.find('iframe')[0]['name']];
				      iframeWin.saveTsorganizationInfo();
				  },
				  cancel: function(){
					  layer.closeAll();
				  }
			});
		});
		//点击修改按钮
		$("#editTestReg").click(function(){
			var selectRow = $("#exampleTableEvents").bootstrapTable('getSelections');
        	var testReg = selectRow[0]; 
        	 if(1 != selectRow.length){
			    layer.msg('请选择您需要修改的检测机构信息！', {icon: 5}); 
			    return ;
	       	} 
			layer.open({
			      type: 2,
			      title: '<span style="color: #ed5565">'+$("#ssbm_name").html()+'修改检测机构【'+testReg.JYJGMC+'】</span>',
			      shadeClose: false, 
			      shade: 0.3,
			      maxmin: false, //开启最大化最小化按钮
			      area: ['75%', '90%'],
			      content: "${WEB_PATH }/reg/tsorganization/view/edit.do?id="+testReg.ID,
			      btn: ['确定','取消'],
			      yes: function(index, layero){
				      var body = layer.getChildFrame('body', index);
				      var iframeWin = window[layero.find('iframe')[0]['name']];
				      iframeWin.updateTsorganizationInfo();
				  },
				  cancel: function(){
					  layer.closeAll();
				  }
			});
		});
        //重置用户密码
        $("#resetTestRegKey").click(function(){
        	var selectRow = $("#exampleTableEvents").bootstrapTable('getSelections');
        	var testReg = selectRow[0]; 
        	 if(1 != selectRow.length){
			    layer.msg('请选择您需要重置的检测机构信息！', {icon: 5}); 
			    return ;
	       	} 
    	  	layer.confirm('尊敬的用户您好：<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red">你确定要重置检测机构为：【'+testReg.JYJGMC+'】的EY(秘钥)吗？</span>',{icon: 3, title:'重置KEY(秘钥)信息提示',btn: ['确定','取消']},
    		function(){
			  	updateResetPassWord(testReg.ID);
			}, function(){
				
			});
        });
        
         //删除检测机构
	     $('#delTestReg').click(function () {
        	var selectRow = $("#exampleTableEvents").bootstrapTable('getSelections');
        	if(0 == selectRow.length){
			    layer.msg('请选择您需要删除的检测机构信息！', {icon: 5}); 
			    return ;
        	}
        	
        	layer.confirm('<span style="color: red">您确定要删除该数据?</span>',{icon: 3, title:'系统提示',btn: ['确认','取消']},
    		function(){
        		$.yilinAjax({
				   	  	type:'POST',
				   	  	url:'${WEB_PATH }/reg/tsorganization/remove.do?id=' + selectRow[0].ID, 
				   	  	data:null,
	            		errorcallback:null,
	            		successcallback:success
				 });
			});
		});
		
		
		function subTableFormatter(index, row, $detail){
			var info = $detail.html('<div id="info"></div>').find('#info');
			info.load("${WEB_PATH}/reg/tsorganization/view/tsorgdetail.do?id="+row.ID);
			tsorgid=row.ID;
			tsorgzbdz=row.ZBDZ;
			setTimeout('TaggingMap()',1500);
		}
		
        function success(result){  
			if(result.success == true){ 
				swal({
			        title: "操作成功",
			        text: result.msg
		    	})
		    	$("#exampleTableEvents").bootstrapTable('refresh');
			}else{
				$('#saveBut').attr("disabled",false);    
				swal({
			        title: "操作失败",
			        text: result.msg
		    	})
			}
		}
		function formatTime(val){
		 	var tt=new Date(val).toLocaleDateString().replace(/年|月/g,"-").replace(/日/g," ");; 
    		return tt; 
		}
		
		function updateResetPassWord(id){
			 $.yilinAjax({
		   	  	type:'POST',
		   	  	loadmsg:'提交中......',
		   	  	url:'${WEB_PATH }/reg/tsorganization/editkey.do', 
		   	  	data:{id:id},
        		errorcallback:null,
        		successcallback:successResetPassWord
		   	});
		}
		
		
		function successResetPassWord(result) { 
			if(result.success == true){
				swal("", result.msg, "success");
				$("#exampleTableEvents").bootstrapTable('refresh');
			}else{
				swal("", result.msg, "error");
			}
		}
		
		
		function formatterStatus(val){
			var auditName = "";
			if(val == "1"){
				auditName = '<span class="label label-primary">正常</span>';
			}else if(val == "2"){
				auditName = '<span class="label label-warning">停业</span>';
			}else if(val == "3"){
				auditName = '<span class="label label-warning">断网</span>';
			} else if(val == "4"){
				auditName = '<span class="label label-danger">注销</span>';
			} 
        	return auditName;
		} 
	 
		
		function TaggingMap(){ 
			var point_value = tsorgzbdz;
			var arr = point_value.split(",");
			var point = new BMap.Point(arr[0],arr[1]);
			var map = new BMap.Map("map_coordinate"+tsorgid); 
			map.centerAndZoom(point == null ? new BMap.Point(85.021158,41.283069, 5):point,16);
			//map.enableScrollWheelZoom();//启动鼠标滚轮缩放地图
			map.enableKeyboard();//启动键盘操作地图
			map.addOverlay(new BMap.Marker(point)); 
	 	}
	 	
	 	
        
    </script>
</body>

</html>